//引入依赖，express是node上的一个web框架
var express = require('express');
var proxy = require('http-proxy-middleware');
var path = require('path');
var app = express();
//创建代理
// app.all("*", function(req, res, next) {
//     // res.header("Access-Control-Allow-Origin",'*');
//     // res.redirect('/')
//     next();
// })
app.use(express.static(__dirname + '/public'))


app.use('/api', proxy({
  "target": "https://www.easy-mock.com/mock/5bbeb39af241aa5f9b318f64/tcrm-react/",
  "changeOrigin": true,
  "pathRewrite": { 
      "^/api": "" 
  },
  "router": {
      // 'admin.onlinepay.interest.zhaogangrentest.com' : 'http://management.onlinepay.interest.zhaogangrentest.com/',
      // 'admin.onlinepay.interest.zhaogangrenuat.com' : 'http://management.onlinepay.interest.zhaogangrenuat.com/',
      // 'admin.onlinepay.interest.zhaogangren.com' : 'http://management.onlinepay.interest.zhaogangren.com/'
  },
}));

app.get('*', function (req, res) {
  res.sendFile(path.join(__dirname, './public/index.html'))
})
app.listen(3000, function () {
    console.log("开始监听");
});